<?php

echo 'invoke - ' . date('Y-m-d H:i:s') . PHP_EOL;

function send($content) {
    $debug = false;
    $token = 'c8b36ffd08650915088ab5850f7ae1287549247cf295a35f1f583924f36994df';
    $secret = 'SECe1ce265cad1bceb1d7dac2ee1f6842cdef3e914ce711be269f10dc38c8297d84';
    if ($debug) {
        $token = 'e7b008d9b17fd0ed2061444b11cb1e9e2bf8d3da8deb43b4b165414ca07fe499';
        $secret = 'SEC47cb25b1e5cd09e002f85e5cdcbe9718e566ede06067d91b75ddc983532bd651';
    }
    $timestamp = time() * 1000;
    $data = $timestamp . "\n" . $secret;
    $signStr = base64_encode(hash_hmac('sha256', $data, $secret, true));
    $sign = utf8_encode(urlencode($signStr));
    $webhook = "https://oapi.dingtalk.com/robot/send?access_token=$token&timestamp=$timestamp&sign=$sign";
    $date = date('Y-m-d H:i:s');
    $msg = [
        'msgtype'   =>  'markdown',
        'markdown'  =>  [
            'title' =>  "点餐通知",
            'text'  =>  $content,
        ],
        'at'    =>  [
            'isAtAll' => true
        ]
    ];
    $json = json_encode($msg, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
    $cmd = "curl -s --location --request POST '$webhook' \
--header 'Content-Type: application/json' \
--data-raw '$json'";
    $rst = exec($cmd);
    $rst = json_decode($rst, true);
    return $rst;
}


send('@所有人 开始点餐吧');
